var api_token = sessionStorage.getItem('api_token'); //参数
var head_title = sessionStorage.getItem('tr_name'); //景区名
var tr_id = sessionStorage.getItem('tr_id'); //景区id
var start_date = sessionStorage.getItem('start_date'); //开始时间
var end_date = sessionStorage.getItem('end_date'); //结束时间
var userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
var http;
if(start_date && end_date){
  http = 'http://c.yueshengkj.com/api/auth/mac?tr_id=' + tr_id + '&start_date=' + start_date + '&end_date=' + end_date; //请求网址
    $('.num_title_1').text('累计采样人数');
    $('.num_title_2').text('');
} else {
  http = 'http://c.yueshengkj.com/api/auth/mac?tr_id=' + tr_id
}
// var numRun1;
var nums1;
// var numRun2;
var nums2;
var pieMax = 100;
var numRun1 = $("#tourists_lose_today").numberAnimate({num: 0, speed: 1000, symbol: ""});
var numRun2 = $(".visitors_year").numberAnimate({num: 0, speed: 1000, symbol: ""});
if(start_date && end_date){
} else {
  setInterval("getAllData(['crowdCount'],0)", 1000 * 10);
  setInterval("getAllData(['hotMap'],0)", 1000 * 900);
  setInterval("getAllData(['tourismResortStayTop'],0)", 1000 * 30);
  setInterval("getAllData(['crowdFlow'],0)", 1000 * 60);
}


function getAllData(arg, show) {
  var ajaxbg = $("#background,#progressBar");
  show = show !== 0;
  $.ajax({
    type: "GET",
    headers: {
      "Authorization": 'Bearer ' + api_token//此处放置请求到的用户token
    },
    async: true,
    url: http,
    cache: false,
    crossDomain: true == !(document.all),
    data: {
      "@action": arg.join(',')
    },
    dataType: "json",
    beforeSend: function () {
      if (show)
        ajaxbg.show();
    },
    success: function (res) {
        ajaxbg.hide();
      if (res.status_code == 200) {
          for (var i = 0; i < arg.length; i++) {
              if (arg[i] == 'crowdCount') {
                  crowdCount(res.data.crowdCount);
              } else if (arg[i] == 'tourismAttractionTop') {
                  tourismAttractionTop(res.data.tourismAttractionTop)
              } else if (arg[i] == 'crowdFlow') {
                  if(start_date && end_date){
                      crowdFlow(res.data.crowdFlowDate)
                  } else {
                      crowdFlow(res.data.crowdFlow)
                  }

              } else if (arg[i] == 'information') {
                  information(res.data.information)
              } else if (arg[i] == 'hotMap') {
                  hotMap(res.data.hotMap)
              } else if (arg[i] == 'tripMode') {
                  setTripMode(res.data.tripMode)
              } else if (arg[i] == 'tourismResortStayTop') {
                  tourismResortStayTop(res.data.tourismResortStayTop)
              }
          }
      } else {
        alert('数据获取失败！');
      }
    },
    error: function (err) {
      console.info('adfasdfasdfasdf')
      var r = confirm(err.responseJSON.error);
      if (r == true) {
        window.location.href = '../login.html'
      } else {
        alert('请自行退出登录！')
      }
      ajaxbg.hide();
      // alert("数据加载失败!");
    }
  });
  // var t = setTimeout(getAllData(['crowdCount']),6000);
}

var maxWithFlag = window.screen.width < 1920;
var fontSize = maxWithFlag ? 10 : 12;
var left = maxWithFlag ? '20%' : '25%';
var itemTop = maxWithFlag ? '-4%' : '-5%';
var itemGap = maxWithFlag ? -10 : -7;
// 头部时间
// console.log('屏幕可用工作区宽度 '+window.screen.availWidth)
// console.log('屏幕分辨率的宽 '+window.screen.width)

// alert(detectZoom());

function mytime() {
  var t = null;
  t = setTimeout(time, 1000); //開始运行
  function time() {
    clearTimeout(t); //清除定时器
    var dt = new Date();
    var y = dt.getFullYear();
    var mt = dt.getMonth() + 1;
    var day = dt.getDate();
    var h = dt.getHours(); //获取时
    var m = dt.getMinutes(); //获取分
    var s = dt.getSeconds(); //获取秒
    document.getElementById("showTime").innerHTML = y + "年" + mt + "月" + day + "日" + h + "时" + m + "分" + s + "秒";
    t = setTimeout(time, 1000); //设定定时器，循环运行
  }
}

// 大数据区分
function information(data) {
  for (var i = 0; i < Object.keys(data).length; i++) {
    if (Object.keys(data)[i] == '性别') {
      setSex(data.性别);
    } else if (Object.keys(data)[i] == '年龄') {
      setAge(data.年龄);
    } else if (Object.keys(data)[i] == '地域') {
      touristDestination(data.地域);
    } else if (Object.keys(data)[i] == '用户兴趣') {
      businessInterests(data.用户兴趣);
    }
  }
}

// 设置采样数据
// 运行
function crowdCount(data) {
  var Today = data.crowdCount; //今日采样
  var Yesterday = data.crowdCountYesterday; //昨日采样
  // 取整
  var dayStr = Number(Today) - Number(Yesterday);
  var dayContrast = Math.abs(Today - Yesterday);
  // 判断dayContrast是否是正值
  if (dayStr >= 0) {
    $('#increase').text('增加');
  } else {
    $("#increase").text('减少')
  }
  // 渲染页面
  // if (Today == sessionStorage.getItem('num1')) {
  // $("#tourists_lose_today").text(Today);
  // } else{
  nums1 = Number(sessionStorage.getItem('num1'));
  nums1 += Number(Today - sessionStorage.getItem('num1'));
  sessionStorage.setItem('num1', Today);
  // numRun1 = $("#tourists_lose_today").numberAnimate({num:Today, speed:1000, symbol:""});
  numRun1.resetData(nums1);
  // }
  $("#yesterday").text(dayContrast);

  var Year = data.crowdCountYear; //今年的客流量
  var YearContrast = data.crowdCountLastYear; //今年明年对比
  // 渲染页面
  // $(".visitors_year").text(Year);
  // if (Year == sessionStorage.getItem('num2')) {
  // $("#tourists_lose_today").text(Today);
  // } else{
  nums2 = Number(sessionStorage.getItem('num2'));
  nums2 += Number(Year - sessionStorage.getItem('num2'));
  sessionStorage.setItem('num2', Year);
  // numRun1 = $("#tourists_lose_today").numberAnimate({num:Today, speed:1000, symbol:""});
  numRun2.resetData(nums2);
  // }
  $("#visitors_year_num").text(YearContrast);
}

// 设置停留时长分布
function tourismResortStayTop(data) {
  var color = ['rgba(47,125,255,1)', 'rgba(241,81,101,1)', 'rgba(0,208,207,1)', 'rgba(255,210,90,1)', 'rgba(241,81,101,1)'];
  var legendData = [], seriesData = [], selected = {};
  if (data && data.length > 0) {
    for (var i = 0; i < data.length; i++) {
      selected[data[i].label] = data[i].value !== 0;
      legendData.push({name: data[i].label, icon: 'circle'});
      seriesData.push(data[i].value);
    }
    var myChart = echarts.init(document.getElementById('year_consume'));
    var option = {
      tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {d}%"
      },
      legend: {
        orient: 'vertical',
        y: 10,
        x: 'left',
        itemWidth: 10,
        itemHeight: 10,
        data: legendData,
        textStyle: {
          color: '#D0EBFF'
        },
        selected: selected,
      },
      series: [
        {
          name: '停留时长',
          type: 'pie',
          center: ['60%', '55%'],
          radius: ['40%', '60%'],
          avoidLabelOverlap: true,
          labelLine: {
            normal: {
              show: true,
              length: 20,
              length2: 70,
              lineStyle: {
                color: '#00DAEE',
                opacity: 0.6,
              },
            },
          },
          label: {
            normal: {
              formatter: function (a) {
                return a.name + ' ' + a.percent.toFixed(0) + '%';
              },
              padding: [0, -70, 30, -70],
              rich: {
                d: {
                  color: '#fff',
                  align: 'center'
                }
              },
              textStyle: {
                color: '#D0EBFF'
              }
            }
          },
          data: []
        }
      ]
    };
    for (var j1 = 0; j1 < seriesData.length; j1++) {
      option.series[0].data.push(
        {
          value: seriesData[j1],
          name: legendData[j1].name,
          textStyle: {
            color: '#fff'
          },
          itemStyle: {
            normal: {
              color: color[j1]

            }
          }
        });

    }
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  }

}

//设置景点客流量排行
function tourismAttractionTop(data) {
  var color = [
    ['rgba(0,208,207,0)', 'rgba(0,208,207,1)'],
    ['rgba(255,144,78,0)', 'rgba(255,144,78,1)'],
    ['rgba(47,125,255,0)', 'rgba(47,125,255,1)'],
    ['rgba(139,59,255,0)', 'rgba(139,59,255,1)'],
    ['rgba(241,81,101,0)', 'rgba(241,81,101,1)']
  ];
  var yAxisData = [], seriesData = [];
  for (var i = 0; i < data.length; i++) {
    yAxisData.push(data[i].ta_name);
    seriesData.push(data[i].crowdCount);
  }
  yAxisData = yAxisData.reverse().slice(0, 5);
  seriesData = seriesData.reverse().slice(0, 5);
  var myChart = echarts.init(document.getElementById('scenic_spot'));
  var option = {
    tooltip: {
      show: true,
      formatter: "{b} <br> {c}人"

    },
    grid: {
      top: -10,
      bottom: '15%',
      left: '15%',
      // x: 50
    },
    xAxis: [{
      type: 'value',
      axisTick: {
        show: false
        // color:'#fff',
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#00DAEE'
        }
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#D0E3FF',
          fontSize: 10
        }
      },
      splitLine: {
        show: false,
        color: '#D0E3FF'
      }
    }],
    yAxis: [{
      type: 'category',
      // data: ['美食', '购物', '门票', '交通', '娱乐'],
      data: yAxisData,
      // minInterval: 1,
      axisTick: {
        // color:'#fff',
        show: false
      },
      axisLine: {
        //  color:'#fff',
        show: true,
        lineStyle: {
          color: '#00DAEE'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#D0E3FF',
          fontSize: 10
        }
      }

    }],
    series: [{
      name: '景点排行',
      type: 'bar',
      barWidth: 10,
      label: {
        normal: {
          show: true,
          position: 'right',
          formatter: '{c}人',
          textStyle: {
            color: '#fff',
            fontSize: '10'
          }
        }
      },
      barCateGoryGap: '20%', //关键第二句：值或为百分比 ‘60%’ ，如果同一类目下的柱间距：barGap:20
      data: []
    }]
  };
  // 使用刚指定的配置项和数据显示图表。
  for (var j = 0; j < seriesData.length; j++) {
    option.series[0].data.push({
      value: seriesData[j],
      name: yAxisData[j],
      itemStyle: {
        normal: {
          barBorderRadius: [0, 10, 10, 0],
          color: {
            type: 'bar',
            colorStops: [{
              offset: 0,
              color: color[j][0] // 0% 处的颜色
            }, {
              offset: 1,
              color: color[j][1] // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false

          }
        }
      }
    });
  }
  myChart.setOption(option);
}

// 消费偏好
function businessInterests(data) {
  var color = [
    ['rgba(0,208,207,0)', 'rgba(0,208,207,0.5)', 'rgba(0,208,207,1)'],
    ['rgba(255,144,78,0)', 'rgba(255,144,78,0.5)', 'rgba(255,144,78,1)'],
    ['rgba(47,125,255,0)', 'rgba(47,125,255,0.5)', 'rgba(47,125,255,1)'],
    ['rgba(139,59,255,0)', 'rgba(139,59,255,0.5)', 'rgba(139,59,255,1)'],
    ['rgba(241,81,101,0)', 'rgba(241,81,101,0.5)', 'rgba(241,81,101,1)']
  ];
  var yAxisData = [], seriesData = [];
  var compare = function (obj1, obj2) {
    var val1 = Number(obj1.占比.replace('%', ''));
    var val2 = Number(obj2.占比.replace('%', ''));
    if (val1 < val2) {
      return -1;
    } else if (val1 > val2) {
      return 1;
    } else {
      return 0;
    }
  };
  var arrData = data.sort(compare).reverse(); //数组对象从小到大排序，使用reverse()方法颠倒排序
  for (var i = 0; i < arrData.length; i++) {
    yAxisData.push(data[i].特征);
    seriesData.push(data[i].占比.replace('%', ''));
  }
  yAxisData = yAxisData.slice(0, 5);
  seriesData = seriesData.slice(0, 5);
  var myChart = echarts.init(document.getElementById('consumption'));
  var option = {
    legend: {
      type: 'scroll',
      orient: 'horizontal',
      show: true,
      zlevel: 1,
      itemWidth: 4,
      itemHeight: 14,
      itemGap: 5,
      textStyle: {
        color: '#D0EBFF',
        fontSize: 14
      },
      data: yAxisData
    },
    tooltip: {
      show: true,
      formatter: "{b} <br> {c}%"
    },
    grid: {
      top: 20,
      bottom: 30,
      x: 30
    },
    xAxis: [{
      type: 'category',
      // data: ['美食', '购物', '门票', '交通', '娱乐'],
      data: yAxisData,
      axisTick: {
        show: false
        // color:'#fff',
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#2495FF'
        }
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#D0E3FF',
          fontSize: 12
        },
        interval: 0,
        formatter: function (value) {
          if (value.length > 3) {
            return value.substring(0, 3) + '...';
          } else {
            return value;
          }
        }
      },
      splitLine: {
        show: false,
        color: '#D0E3FF'
      }

    }],
    yAxis: [{
      type: 'value',
      minInterval: 1,
      axisTick: {
        // color:'#fff',
        show: false
      },
      axisLine: {
        //  color:'#fff',
        show: true,
        lineStyle: {
          color: '#2495FF'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#D0E3FF',
          fontSize: 12
        }
      },
      splitLine: {
        show: false
      }

    }],
    series: [{
      type: 'bar',
      barWidth: 14,
      label: {
        normal: {
          show: true,
          position: 'top',
          formatter: '{c}%',
          textStyle: {
            color: '#fff',
            fontSize: '12'
          }
        }
      },
      data: []
    }]
  };
  for (var j1 = 0; j1 < yAxisData.length; j1++) {
    option.series[0].data.push(
      {
        name: yAxisData[j1],
        type: 'bar',
        value: seriesData[j1],
        itemStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(
              1, 0, 0, 1,
              [{
                offset: 1,
                color: color[j1][0]
              }, {
                offset: 0.5,
                color: color[j1][1]
              },
                {
                  offset: 0,
                  color: color[j1][2]
                }
              ]
            )
          }
        }
      });
  }
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

// 日客流量
function crowdFlow(data) {
  var xAxisData = [], seriesData = [];
  for (var i = 0; i < data.length; i++) {
    xAxisData.push(data[i].time);
    seriesData.push(data[i].crowdCount);
  }
  var myChart = echarts.init(document.getElementById('passenger'));
  var option = {
    title: {
      text: '',
      textStyle: {
        fontWeight: 'normal',
        fontSize: 12,
        color: '#F1F1F3'
      },
      left: '6%'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          color: '#57617B'
        }
      }
    },
    grid: {
      left: '4%',
      right: '2%',
      bottom: '2%',
      top: '10%',
      containLabel: true
    },
    xAxis: [{
      type: 'category',
      boundaryGap: false,
      axisLine: {
        lineStyle: {
          color: '#00DAEE'
        }
      },
      // data:['2点10分','3点10分','4点10分','5点10分','6点10分','7点10分','8点10分'] ,
      data: xAxisData,
      axisLabel: {
        interval: 0,
        rotate: 50,
        textStyle: {
          color: '#D0EBFF',
          fontSize: 10
        }
      }
    }],
    yAxis: [{
      type: 'value',
      // interval: 40,
      splitNumber: 2,
      axisTick: {
        show: false
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#00DAEE'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#D0EBFF',
          fontSize: 10
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: 'rgba(216,216,216,1)',
          opacity: 0.1381,
        }
      },
    }],
    series: [{
      name: '',
      type: 'line',
      smooth: true,
      lineStyle: {
        normal: {
          width: 2
        }
      },
      areaStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: 'rgba(82, 191, 255, 0.3)'
          }, {
            offset: 0.8,
            color: 'rgba(82, 191, 255, 0)'
          }], false),
          shadowColor: 'rgba(228, 139, 76, 0.1)',
          shadowBlur: 10
        }
      },
      symbolSize: 4,
      itemStyle: {
        normal: {
          color: '#71FFD5',
          borderColor: '#e48b4c'
        }
      },
      data: seriesData
    }]
  };
  myChart.setOption(option);
}

// 性别
function setSex(data) {
  var legendData = [];
  var man, woman;
  var array = data;
  for (var i = 0; i < array.length; i++) {
    if (array[i].特征 == '男性') {
      legendData.push(array[i].特征);
      man = array[i].占比.replace('%', '')
    } else if (array[i].特征 == '女性') {
      legendData.push(array[i].特征);
      woman = array[i].占比.replace('%', '');
    }

  }
  var myChart = echarts.init(document.getElementById('gender'));
  var placeHolderStyle = {
    normal: {
      color: "rgba(0,0,0,0)",
      borderWidth: 0
    }
  };
  var option = {
    title: {
      text: "游客性别",
      textStyle: {
        color: '#D0EBFF',
        fontSize: 14
      },
      bottom: '2%',
      x: 'center'
    },
    color: ['#2F7DFF', '#F15165'],
    tooltip: {
      trigger: 'item',
      formatter: "{a}:<br/>{b}",

    },
    legend: {
      type: 'scroll',
      orient: 'vertical',
      left: left,
      top: itemTop,
      itemWidth: 0,
      itemHeight: 0,
      itemGap: itemGap,
      textStyle: {
        color: '#D0EBFF',
        fontSize: fontSize,
      },
      data: legendData
    },
    series: [{
      name: '男性',
      type: 'pie',
      clockWise: true,
      center: ['50%', '45%'],
      radius: ['80%', '87%'],
      itemStyle: {
        normal: {
          label: {
            show: false,
            textStyle: {
              fontSize: 24
            }
          },
          labelLine: {
            show: false
          },
          borderColor: "#2F7DFF",
        }
      },
      data: [{
        value: man,
        name: man + '%'
      }, {
        value: pieMax - man,
        name: '',
        itemStyle: placeHolderStyle
      }]
    }, {
      name: '女性',
      type: 'pie',
      clockWise: true,
      center: ['50%', '45%'],
      radius: ['65%', '72%'],
      itemStyle: {
        normal: {
          label: {
            show: false,
            textStyle: {
              fontSize: 24
            }
          },
          labelLine: {
            show: false
          },
          borderColor: "#F15165",
        }
      },
      data: [{
        value: woman,
        name: woman + '%'
      }, {
        value: pieMax - woman,
        name: '',
        itemStyle: placeHolderStyle
      }]
    }]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

// 年龄
function setAge(data) {
  var legendData = [], selected = {};
  var age1, age2, age3, age4, age5, age6, age7, name1, name2, name3, name4, name5, name6, name7;
  var array = data;
  for (var i = 0; i < array.length; i++) {
    selected[array[i].特征] = parseInt(array[i].占比) !== 0;
    if (array[i].特征 == '<18岁') {
      age1 = array[i].占比.replace('%', '');
      name1 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '18~23岁') {
      age2 = array[i].占比.replace('%', '');
      name2 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '24~30岁') {
      age3 = array[i].占比.replace('%', '');
      name3 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '31~40岁') {
      age4 = array[i].占比.replace('%', '');
      name4 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '41~50岁') {
      age5 = array[i].占比.replace('%', '');
      name5 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '51~65岁') {
      age6 = array[i].占比.replace('%', '');
      name6 = array[i].特征;
      legendData.push(array[i].特征);
    } else if (array[i].特征 == '66~127岁') {
      age7 = array[i].占比.replace('%', '');
      name7 = array[i].特征;
      legendData.push(array[i].特征);
    }

  }
  var myChart = echarts.init(document.getElementById('age'));
  var placeHolderStyle = {
    normal: {
      color: "rgba(0,0,0,0)",
      borderWidth: 0
    }
  };
  var option = {
    title: {
      text: "游客年龄",
      textStyle: {
        color: '#D0EBFF',
        fontSize: 14
      },
      bottom: '2%',
      x: 'center'
    },
    color: ['#2F7DFF', '#FFD25A', '#AD7EED', '#00D0CF', "#F15165", "#FF9454", "#27ff00"],
    tooltip: {
      trigger: 'item',
      formatter: "{a}:<br/>{b}"
    },
    legend: {
      type: 'scroll',
      orient: 'vertical',
      left: left,
      // right: '0%',
      top: itemTop,
      itemWidth: 0,
      itemHeight: 0,
      itemGap: itemGap,
      textStyle: {
        color: '#D0EBFF',
        fontSize: fontSize
      },
      data: legendData,
      selected: selected,
    },
    series: [
      {
        name: name1,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['80%', '87%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age1,
            name: age1 + '%'
          }, {
            value: pieMax - age1,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name2,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['67%', '74%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age2,
            name: age2 + '%'
          }, {
            value: pieMax - age2,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name3,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['54%', '61%'],
        itemStyle: {
          normal: {
            label: {
              show: false
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age3,
            name: age3 + '%'
          }, {
            value: pieMax - age3,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name4,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['41%', '48%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age4,
            name: age4 + '%'
          }, {
            value: pieMax - age4,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name5,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['28%', '35%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age5,
            name: age5 + '%'
          }, {
            value: pieMax - age5,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name6,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['15%', '22%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age6,
            name: age6 + '%'
          }, {
            value: pieMax - age6,
            name: '',
            itemStyle: placeHolderStyle
          }]
      },
      {
        name: name7,
        type: 'pie',
        center: ['50%', '45%'],
        radius: ['2%', '9%'],
        itemStyle: {
          normal: {
            label: {
              show: false,
              textStyle: {
                fontSize: 24
              }
            },
            labelLine: {
              show: false
            },
            shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
          }
        },
        data: [
          {
            value: age7,
            name: age7 + '%'
          }, {
            value: pieMax - age7,
            name: '',
            itemStyle: placeHolderStyle
          }]
      }
    ]
  };
  myChart.setOption(option);

}

// 出行方式
function setTripMode(data) {
  var legendData = [];
  var man, woman;
  var array = data;
  for (var i = 0; i < array.length; i++) {
    if (array[i].dvc_name == '自驾游') {
      driver = array[i].countPercentage.replace('%', '');
    } else if (array[i].dvc_name == '团队游') {
      team = array[i].countPercentage.replace('%', '');
    }
    legendData.push(array[i].dvc_name);
  }
  legendData.reverse();
  var myChart = echarts.init(document.getElementById('getting_around'));
  var placeHolderStyle = {
    normal: {
      color: "rgba(0,0,0,0)",
      borderWidth: 0
    }
  };
  var option = {
    title: {
      text: "出行方式",
      textStyle: {
        color: '#D0EBFF',
        fontSize: 14
      },
      bottom: '2%',
      x: 'center'
    },
    color: ['#2F7DFF', '#F15165'],
    tooltip: {
      trigger: 'item',
      formatter: "{b}"
    },
    legend: {
      type: 'scroll',
      orient: 'vertical',
      left: left,
      top: itemTop,
      itemWidth: 0,
      itemHeight: 0,
      itemGap: itemGap,
      textStyle: {
        color: '#D0EBFF',
        fontSize: fontSize
      },
      data: legendData
    },
    series: [{
      name: '自驾游',
      type: 'pie',
      clockWise: true,
      center: ['50%', '45%'],
      radius: ['80%', '87%'],
      itemStyle: {
        normal: {
          label: {
            show: false,
            textStyle: {
              fontSize: 24
            }
          },
          labelLine: {
            show: false
          },
        }
      },
      data: [{
        value: driver,
        name: driver + '%'
      }, {
        value: pieMax - driver,
        name: '',
        itemStyle: placeHolderStyle
      }]
    }, {
      name: '团队游',
      type: 'pie',
      clockWise: true,
      center: ['50%', '45%'],
      radius: ['65%', '72%'],
      itemStyle: {
        normal: {
          label: {
            show: false,
            textStyle: {
              fontSize: 24
            }
          },
          labelLine: {
            show: false
          },
        }
      },
      data: [{
        value: team,
        name: team + '%',
        color: '#F15165',
      }, {
        value: pieMax - team,
        name: '',
        itemStyle: placeHolderStyle
      }]
    }]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);
}

// 景区热力图
function hotMap(data) {
  var map = new BMap.Map("my_heat_map");          // 创建地图实例
  var points = data;
  var point = new BMap.Point(userInfo.bindResort.longitude, userInfo.bindResort.latitude);
  map.setMapStyle({style: 'dark'});
  var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
  map.addControl(top_left_navigation);
  map.addControl(new BMap.MapTypeControl());
  if (userInfo.bindResort.more) {
    map.centerAndZoom(point, Number(userInfo.bindResort.more.map_range));             // 初始化地图，设置中心点坐标和地图级别   5-19
  } else {
    map.centerAndZoom(point, 15);             // 初始化地图，设置中心点坐标和地图级别   5-19
  }
  map.enableScrollWheelZoom(); // 允许滚轮缩放
  if (!isSupportCanvas()) {
    alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
  }
  var heatmapOverlay = new BMapLib.HeatmapOverlay({"radius": 20, "visible": true, "opacity": 0.3});
  map.addOverlay(heatmapOverlay);
  heatmapOverlay.setDataSet({data: points, max: 1000});
  //判断浏览区是否支持canvas
  var gradient = {
    0: '#0c1aff',
    .4: '#33d60d',
    .7: '#FBF81F',
    1: '#F8260D'
  };

  heatmapOverlay.setOptions({"gradient": gradient});

  //判断浏览区是否支持canvas
  function isSupportCanvas() {
    var elem = document.createElement('canvas');
    return !!(elem.getContext && elem.getContext('2d'));
  }
}

//客户来源
function touristDestination(data) {
  var yDatas = [];
  var datas = [];
  var yDatas2 = [];
  var datas2 = [];
  var objArr = [];
  var lengthData = [];
  var lengthData2 = [];
  var array = data;
  for (var i = 0; i < array.length; i++) {
    var province = array[i].特征.indexOf('省');
    var district = array[i].特征.indexOf('区');
    var city = array[i].特征.indexOf('市');
    if (province > 0 || district > 0 || city > 0) {
      objArr.push({
        num: parseInt(array[i].占比),
        city: array[i].特征,
        length: 100
      })
    }
  }
  // console.log("我是objArr",objArr);
  // 数组对象排序
  var compare = function (obj1, obj2) {
    var val1 = obj1.num;
    var val2 = obj2.num;
    if (val1 < val2) {
      return -1;
    } else if (val1 > val2) {
      return 1;
    } else {
      return 0;
    }
  };
  var arrData = objArr.sort(compare).reverse(); //数组对象从小到大排序，使用reverse()方法颠倒排序
  var arrayData1 = arrData.slice(0); //截取数组前十
  // var arrayData2 = arrData.slice(9, 16); //截取数组前十
  var arrayData = arrayData1.slice(0, 6).reverse();
  var arrayData2 = arrayData1.slice(6, 12).reverse();
  // 循环arrData数组
  for (var j = 0; j < arrayData.length; j++) {
    yDatas.push(arrayData[j].city);
    datas.push(arrayData[j].num);
    lengthData.push(arrayData[j].length)
  }
  var myChart = echarts.init(document.getElementById('source_bar1'));
  var myChartWidth = parseInt(window.getComputedStyle(document.getElementById('source_bar1')).width);
  var option = {
    grid: {
      left: '40%',
      right: 10,
      top: 0,
      bottom: 0,
      width: myChartWidth * 0.4,
      // width:'50%',
      // x: 60
    },
    tooltip: {
      show: true,
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      },
      textStyle: {
        align: "left",
        fontSize: 18,
        color: "#fff",
        fontStyle: "normal",
        fontWeight: "normal",
        fontFamily: "sans-serif"
      },
      extraCssText: "box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.2)",
      showContent: true,
      alwaysShowContent: false,
      backgroundColor: "rgba(50,50,50,0.7)",
      borderColor: "#333"
    },
    xAxis: {
      type: "value",
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: false,
        textStyle: {
          color: '#fff',
          fontSize: 10
        }
      },
      axisTick: {
        show: false
      },
    },
    yAxis: {
      type: "category",
      offset: 10,
      axisLine: {
        show: false,
        lineStyle: {
          color: '#B3AFA1'
        }
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#D0E3FF',
          fontSize: 12
        },
        interval: 0,
        formatter: function (value) {
          if (value.length > 4) {
            return value.substring(0, 2) + '...';
          } else {
            return value;
          }
        }
      },
      data: yDatas
    },
    series: [{
      type: "bar",
      barWidth: "7",
      stack: "b",
      tooltip: {
        show: true
      },
      itemStyle: {
        normal: {
          barBorderRadius: 6,
          color: new echarts.graphic.LinearGradient(1, 0, 0, 1, [{
            offset: 0,
            color: '#71FFD5'
          }, {
            offset: 1,
            color: '#0079FF'
          }])
        },
      },
      label: {
        normal: {
          show: true,
          position: [myChartWidth * 0.45, '-110%'],
          formatter: function (param) {
            return param.value + '%';
          },
          textStyle: {
            color: '#71FFD5',
            fontSize: '12',
          }
        }
      },
      data: datas
    },
      {
        name: 'custom',
        tooltip: {
          show: true
        },
        "type": "bar",
        "barWidth": 12,
        "barGap": "-135%",
        "itemStyle": {
          "normal": {
            "barBorderRadius": 30,
            "color": "rgba(0,0,0,0)",
            "borderWidth": 1,
            "borderColor": "rgba(0,176,255,.7)"
          }
        },
        "data": lengthData,
        "z": 0,
      }
    ]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);

  for (var j2 = 0; j2 < arrayData2.length; j2++) {
    yDatas2.push(arrayData2[j2].city);
    datas2.push(arrayData2[j2].num);
    lengthData2.push(arrayData2[j2].length);
  }
  var myChart2 = echarts.init(document.getElementById('source_bar2'));
  var myChart2Width = parseInt(window.getComputedStyle(document.getElementById('source_bar2')).width);
  var option2 = {
    grid: {
      left: '30%',
      right: 10,
      top: 0,
      bottom: 0,
      width: myChart2Width * 0.4,
      // x: 60
    },
    tooltip: {
      show: true,
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      },
      textStyle: {
        align: "left",
        fontSize: 18,
        color: "#fff",
        fontStyle: "normal",
        fontWeight: "normal",
        fontFamily: "sans-serif"
      },
      extraCssText: "box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.2)",
      showContent: true,
      alwaysShowContent: false,
      backgroundColor: "rgba(50,50,50,0.7)",
      borderColor: "#333"
    },
    xAxis: {
      type: "value",
      // max:myChart2Width*0.5,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: false,
        textStyle: {
          color: '#fff',
          fontSize: 10
        }
      },
      axisTick: {
        show: false
      }
    },
    yAxis: {
      type: "category",
      offset: 0,
      axisLine: {
        show: false,
        lineStyle: {
          color: '#B3AFA1'
        }
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          color: '#D0E3FF',
          fontSize: 12
        },
        interval: 0,
        formatter: function (value) {
          if (value.length > 4) {
            return value.substring(0, 2) + '...';
          } else {
            return value;
          }
        }
      },
      data: yDatas2
    },
    series: [{
      type: "bar",
      barWidth: 6,
      stack: "b",
      tooltip: {
        show: true
      },
      itemStyle: {
        normal: {
          barBorderRadius: 6,
          color: new echarts.graphic.LinearGradient(1, 0, 0, 1, [{
            offset: 0,
            color: '#71FFD5'
          }, {
            offset: 1,
            color: '#0079FF'
          }])
        }
      },
      label: {
        normal: {
          show: true,
          // position: [80, -7],
          position: [myChart2Width * 0.45, '-110%'],

          formatter: function (param) {
            return param.value + '%';
          },
          textStyle: {
            color: '#71FFD5',
            fontSize: '12'
          }
        }
      },
      data: datas2
    },
      {
        name: '',
        tooltip: {
          show: true
        },
        "type": "bar",
        "barWidth": 12,
        "barGap": "-135%",
        "itemStyle": {
          "normal": {
            "barBorderRadius": 30,
            "color": "rgba(0,0,0,0)",
            "borderWidth": 1,
            "borderColor": "rgba(0,176,255,.7)"
          }
        },
        "data": lengthData2,
        "z": 0
      }
    ]
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart2.setOption(option2);
}

// dom创建自执行
$(function () {
  $('#header-title').text(head_title);
  //当前时间
  mytime();
  //首页所有数据请求
  getAllData(['hotMap', 'crowdCount', 'tourismResortStayTop', 'tourismAttractionTop', 'crowdFlow', 'information', 'tripMode']);
  // 监听a链接
  $('#quitBtn>a').on('click', function () {
    sessionStorage.clear(); //清除sessionStorage
  });
})